package com.skirmisher.inspection.conform.controller;

import com.skirmisher.inspection.common.utils.PageUtils;
import com.skirmisher.inspection.conform.entity.InsConformJob;
import com.skirmisher.inspection.conform.entity.InsConformJobQueryEntity;
import com.skirmisher.inspection.conform.service.InsConformJobService;
import com.skirmisher.inspection.daily.entity.InsDailyJobQueryEntity;
import com.skirmisher.inspection.inspection.testController.ResponseModel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName InsConformJobAppController
 * @Description TODO
 * @Author hanwangxin
 * @Date 2020/12/17 下午8:59
 * @Version 1.0
 */
@Api(tags = "符合巡查任务App接口")
@RestController
@RequestMapping("/app_conformJob")
public class InsConformJobAppController {

    @Autowired
    private InsConformJobService insConformJobService;

    @ApiOperation(value = "获取符合巡查任务详情")
    @ApiImplicitParam(name = "jobId",value = "任务id",required = true)
    @GetMapping(value = "/getJobDetail")
    public ResponseModel getJobDetail(String jobId){
        ResponseModel responseModel = new ResponseModel();
        if (StringUtils.isEmpty(jobId)){
            responseModel.setCode(201);
            responseModel.setMessage("无模板id");
            return responseModel;
        }
        InsConformJob job = insConformJobService.getJobDetail(jobId);
        responseModel.setData(job);
        return  responseModel;
    }

    @ApiOperation(value = "巡查任务页面查询")
    @GetMapping(value = "/getJobPageData")
    public ResponseModel getJobPageData(InsConformJobQueryEntity query){

        ResponseModel responseModel = new ResponseModel();
        //参数校验
        Integer startRow = PageUtils.getStartRow(query.getPage(), query.getRows());
        if (startRow == null || startRow < 0){
            responseModel.setCode(201);
            responseModel.setMessage("分页参数有误");
            return  responseModel;
        }

        query.setStartRows(startRow);
        insConformJobService.getJobPageData(query);
        responseModel.setDataDataGrid(query.getDateList(), query.getCount());


        return responseModel;
    }

    /**
     * @Author hanwangxin
     * @Description //TODO 开启任务 * @Date 下午4:30 2020/12/13
     * @Param [jobId]
     * @return com.skirmisher.inspection.inspection.testController.ResponseModel
     **/
    @ApiOperation(value = "app开启任务")
    @PostMapping(value = "/startJob")
    public ResponseModel startJob(String jobId){

        ResponseModel responseModel = new ResponseModel();
        if (StringUtils.isEmpty(jobId)){
            responseModel.setCode(201);
            responseModel.setMessage("无任务id");
            return  responseModel;
        }
        insConformJobService.startJob(jobId);
        return responseModel;
    }

    /**
     * @Author hanwangxin
     * @Description //TODO 结束任务 * @Date 下午4:37 2020/12/13
     * @Param [jobId]
     * @return com.skirmisher.inspection.inspection.testController.ResponseModel
     **/
    @ApiOperation(value = "app结束任务")
    @PostMapping(value = "/endJob")
    public ResponseModel endJob(String jobId){
        ResponseModel responseModel = new ResponseModel();
        if (StringUtils.isEmpty(jobId)){
            responseModel.setCode(201);
            responseModel.setMessage("无任务id");
            return  responseModel;
        }
        insConformJobService.endJob(jobId);
        return responseModel;
    }
}
